#include"Commd.hpp"
#include<unistd.h>
//向管道中读还是写，取决于调用什么函数
int main()
{
    Fifo fifo(Path);//创建管道
    int rfd = open(Path,O_RDONLY);//打开管道文件
    if(rfd < 0)
    {
        cerr << "open failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
        return 1;
    }
    cout << "open success" << endl;
    char buffer[1024];
    while(true)
    {
        ssize_t n = read(rfd,buffer,sizeof(buffer));//读取管道中的数据
        if(n > 0)
        {
            buffer[n] = 0;//添加结尾
            cout<<"client say: "<<buffer<<endl;
        }
        else if(n == 0)//当read返回0时，说明管道的写端已经关闭了
        {
            cout<< "client quit , me too !"<<endl;
            break;
        }
        else
        {
            cerr << "read failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
            break;
        }
    }
    close(rfd);
    return 0;
}